﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wpf="clr-namespace:ViewOnCore.Helper.WPF">

    <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid VerticalAlignment="Stretch">
                        <Grid.Resources>
                            <wpf:ArithmeticConverter x:Key="arithmeticConverter" />
                        </Grid.Resources>
                        <Border
                            Name="PART_Track"
                            CornerRadius="2"
                            Background="{DynamicResource VOColor15}"
                            BorderBrush="{DynamicResource VOColor17}"
                            BorderThickness="1"/>
                        <Border
						  Name="PART_Indicator"
						  CornerRadius="2"
						  Background="{DynamicResource VOColor02}"
						  BorderThickness="1"
						  HorizontalAlignment="Left" />

                        <!-- Animation -->
                        <Rectangle x:Name="Animation" MaxHeight="25" ClipToBounds="True" RadiusX="2" RadiusY="2">
                            <Rectangle.Fill>
                                <DrawingBrush Stretch="None" TileMode="Tile" Viewbox="0,0,1,1" Viewport="0,0,25,25" ViewportUnits="Absolute">
                                    <DrawingBrush.RelativeTransform>
                                        <TranslateTransform X="0" Y="0"/>
                                    </DrawingBrush.RelativeTransform>
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing Geometry="M10,0 25,0 15,25 0,25 Z" Brush="{DynamicResource VOColor02}"/>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Rectangle.Fill>
                            <Rectangle.Triggers>
                                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation
                                                Duration="0:0:30"
                                                From="0"
                                                RepeatBehavior="Forever"
                                                Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TranslateTransform.X)"
                                                To="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Rectangle}}, Path=ActualWidth}"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Rectangle.Triggers>
                        </Rectangle>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsIndeterminate" Value="True">
                            <Setter Property="Visibility" TargetName="Animation" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="PART_Track" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="PART_Indicator" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="False">
                            <Setter Property="Visibility" TargetName="Animation" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="PART_Track" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="PART_Indicator" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>